package com.android.datn.activities.offline;

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Toast;

@SuppressWarnings("deprecation")
public class GActivityOffline extends ActivityGroup {
	private Handler handler = new Handler();
	public static GActivityOffline group;
	public static ArrayList<View> arrList;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		GActivityOffline.arrList = new ArrayList<View>();
		group = this;
		View view = getLocalActivityManager().startActivity(
				"Offline",
				new Intent(this, AOffline.class)
						.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
				.getDecorView();
		replaceView(view);
	}

	public void replaceView(View view) {
		arrList.add(view);
		setContentView(view);
	}

	public void back() {
		if (arrList.size() > 1) {
			arrList.remove(arrList.size() - 1);
			if (arrList.size() == 2) {
				try {
					AArtist.artist.onItemReClick();
				} catch (Exception e) {
					// TODO: handle exception
				}
				try {
					AAlbum.album.onItemReClick();
				} catch (Exception e) {
					// TODO: handle exception
				}
				
			}
			View view = arrList.get(arrList.size() - 1);
			setContentView(view);
			// }
		} else {
			this.finish();
		}
	}

	@Override
	public void onBackPressed() {
		GActivityOffline.group.back();
	}
}
